package zuo.algo.c05;

import zuo.algo.data.LinkedNode;
import zuo.algo.util.LinkedUtils;

/**
 * 01:13-打印两个有序链表的公共部分
 */
public class LinkedPrint {

    public static void print(LinkedNode head1, LinkedNode head2) {
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                head1 = head1.next;
            } else if (head1.val > head2.val) {
                head2 = head2.next;
            } else {
                System.out.println(head1.val);
                head1 = head1.next;
                head2 = head2.next;
            }
        }
    }

    public static void main(String[] args) {
        LinkedNode head1 = LinkedUtils.constructLinkedList(new int[]{1, 2, 5, 6, 9});
        LinkedNode head2 = LinkedUtils.constructLinkedList(new int[]{0, 2, 4, 6, 9});
        print(head1, head2);
    }
}
